using System;
using System.Collections;
using System.Runtime.CompilerServices;
using Awaiter;
using Minions.Classes;
using Nsb.Classes;
using jQueryApi;

namespace MinionsEdit.Classes
{
    [IgnoreNamespace]
    public static class MiMapActions
    {
        public static void EditMinionProps(Evo evo)
        {
            MinionEdit mm = (MinionEdit) evo.Value;
            new Await()
                .AddAw(new EditProps().EditDAw, mm.Data)
                .AddAw(DomElement.RequireResultAw, DomElement.NotFail)
                .AddDl(
                    delegate(Await aw)
                    {
                        //try
                        //{
                        Dictionary result = (Dictionary) aw.Result;
                        // Could return the full gig or just the gig's css
                        if (Type.HasField(result, "css"))
                        {
                            mm.Data = (MinionData) (object) result;
                        }
                        else
                        {
                            mm.Data.css = result;
                        }
                        new Evo().FireWith(mm.RePaintAndSave);
                        //}
                        //catch (Exception ex)
                        //{
                        //    Inform.Error("Exception updating minion css: {0}", ex);
                        //}
                    }
                )
                .Commit();
        }

        public static void CopySlideEv(jQueryEvent e)
        {
            //List<MinionData> items = new List<MinionData>();
            //foreach (KeyValuePair<string, MinionData> p in MinionEdit.ActiveFocus.LiveData)
            //{
            //    items.Add(p.Value);
            //}
            //Storage.SetLocal("CopyBuffer", items);
            //new Await().AddFn(RedrawPageGear).Commit();
        }
    }
}